
using System;

namespace Pisces
{
    /**
     * 无锁的单例，用于单线程
     */
    public abstract class UnlockSingleton<T> where T : class, InterfaceEntityLiftcycle
    {
        protected static T singleton;
        
        public static T getSingleton()
        {
            if (singleton == null)
            {
                singleton = Activator.CreateInstance<T>();
                singleton.onInit();
            }
            return singleton;
        }

        public void destroy()
        {
            singleton = default(T);
            singleton.onDestroy();
        }
    }
}